
const DistInitPlugin = require('./config/plugin/DistInitPlugin.js');
const DistEndPlugin = require('./config/plugin/DistEndPlugin.js');
const FailedPlugin = require('./config/plugin/FailedPlugin.js');
const DonePlugin = require('./config/plugin/DonePlugin.js');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const devServer = require('./config/devServer.js')

let vueConfig = {
    runtimeCompiler: true,
    lintOnSave: false, // eslint关闭
    productionSourceMap: false, // map 映射
    assetsDir: "static",
    // publicPath: '/c',
    publicPath: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_CDNURL: '',
    transpileDependencies: ["./src"],

    chainWebpack: config => {
        config.plugin("html").tap(args => {
            args[0].minify = false;
            return args;
        });
        if (process.env.NODE_ENV === 'production') {
            config.plugin('extract-css')
                .tap(args => [{
                    filename: `static/css/[name]_[hash].css`,
                    chunkFilename: `static/css/[name]_[hash].css`
                }])
        }

    },
    configureWebpack: {
        plugins: [
            new DistInitPlugin(),
            new DistEndPlugin(),
            new FailedPlugin(),
            new DonePlugin(),
        ],
        resolve: {},
        optimization: {
            minimizer: [
                new UglifyJsPlugin({
                    uglifyOptions: {
                        compress: {
                            // warnings: false,
                            drop_console: true, //console
                            drop_debugger: false,
                            pure_funcs: ['console.log'] //移除console
                        }
                    }
                })
            ]
        },
        output: {
            filename: `static/js/[name]_[hash].js?`,
            chunkFilename: `static/js/[name]_[hash].js`
        },
    },
    outputDir: "dist",
    devServer: devServer,
    css: {
        loaderOptions: {}
    }
};

module.exports = vueConfig;